<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<script type="text/javascript">

	function aa(){
		
		var deptid=$('#deptid').val();
		
		$.pdialog.reload('<%=basePath%>allocaterequest/getfromdept.do?deptid='+deptid,{dialogId:'submit'});
	}
	function cl(){
		if(!c())
		alertMsg.warn('请选择商品信息');
	}
	

	function c(){
		var check=document.getElementsByTagName("input");
		for(var i=0;i<check.length;i++){
		if(check[i].type=='checkbox'&&check[i].checked){
		return true;
		}
		}
		return false;
	}
	
	function cc(obj,sum){
		var value=$(obj).val();
		if(value=='0'||value>sum){
			alertMsg.warn('调拨数量不能为0和不能大于总数量');
			$('#t1').attr("disabled", true);}
		else{
			$('#t1').attr("disabled", false);
		var check=$(obj).parent().parent().parent().children().first().next().children().first().children().first();
		var cvalue=check.val();
		var ss=cvalue.split(",");
		check.val(ss[0]+","+ss[1]+","+value);	}
	}
	
</script>
<form onsubmit="return c()&&validateCallback(this,navTabAjaxDone)" action="allocaterequest/insertrequest.do" method="post">

<div class="pageHeader">
	<div class="searchBar">
		<table class="searchContent">
			<tr>
				<td>
					申请部门：<input type="hidden" name="deptid" value="${requestScope.dept.deptid }"  />
					<input type="text" value="${requestScope.dept.name }" readonly />
				</td>
				
				<td>
					源部门：<input class="required" bringbackname="district.deptid"  name="from_dept" id="deptid" type="hidden" var=""  value="${requestScope.dept2.deptid }"  onchange="aa()" />
					<input class="required" bringbackname="district.deptname"  type="text"  value="${requestScope.list[0].name }" id="deptname" readonly />
				</td>
				<td>
				<a class="btnLook" href="<%=basePath%>dept/showtree.do" lookupGroup="district">查找带回</a>	
				</td>
				</tr>
				<tr>
				<td>
					目标部门：<input class="required" bringbackname="district2.deptid"  name="to_dept" type="hidden"   var="" id="to_dept" />
					<input class="required" bringbackname="district2.deptname" type="text"  readonly/>
				</td>
				<td>
				<a class="btnLook" href="<%=basePath%>dept/showtree.do" lookupGroup="district2">查找带回</a>	
				</td>
				
			</tr>
		</table>
	</div>
	
</div>
<div class="pageContent">
	
	<table class="table" width="100%" layoutH="138">
		<thead>
			<tr>
				<th width="20"></th>
				<th width="20"></th>
				<th width="120">商品流水号</th>
				<th width="150">商品名称</th>
				<th>当前仓库</th>
				<th width="50">总数量</th>
				<th width="50">调拨数量</th>
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${requestScope.list }" var="all" varStatus="count">
		<tr>
		<td>${count.index+1 }</td>
		<td><input type="checkbox" name="ids" value="${all.id },${all.sum},1"></td>
		<td>${all.code }</td>
		<td>${all.goodname }</td>
		<td>${all.name }</td>
		<td>${all.sum }</td>
		<td><input type="text" name="allocatenum" value="1" style="border:none" 
		onchange="cc(this,${all.sum })"></td>
		</tr>
		
		</c:forEach>
		</tbody>
	</table>
	</div>
	<div class="formBar">
		<ul>
			<li><div class="buttonActive">
					<div class="buttonContent">
						<button type="submit" onclick="cl()" id='t1'>保存</button>
					</div>
				</div></li>
			<li>
				<div class="button">
					<div class="buttonContent">
						<button type="reset" >重置</button>
					</div>
				</div>
			</li>
		</ul>
	</div>

</form>